package com.demo.order.service.impl;

import com.demo.common.base.constant.SysConstant;
import com.demo.common.base.pojo.JsonRes;
import com.demo.store.bo.CreateStoreBO;
import com.demo.store.vo.StoreMainVO;
import com.demo.order.service.DispatchRemoteStoreMainService;
import com.demo.store.remote.RemoteStoreMainService;
import com.demo.user.exception.DemoUserException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 调用RemoteUserMainServiceImpl实现
 *
 * @author DayDayUp
 * create on 2023-05-18
 **/
@Service
public class DispatchRemoteStoreMainServiceImpl implements DispatchRemoteStoreMainService {
    @Resource
    private RemoteStoreMainService remoteStoreMainService;

    /**
     * 分页获取用户信息
     * @param id 查询参数
     * @return Page<UserMainVO>
     */
    @Override
    public StoreMainVO getOneStoreMain(Long id){
        JsonRes<StoreMainVO> jsonRes = remoteStoreMainService.getOneStoreMain(id);
        if (Objects.isNull(jsonRes) || !Objects.equals(SysConstant.SUCCESS, jsonRes.getStatus()) || Objects.isNull(jsonRes.getData()) ) {
            return null;
        }
        return jsonRes.getData();
    }

    /**
     * 创建库存信息
     * @param createStoreBO 参数
     */
    @Override
    public void createStore(CreateStoreBO createStoreBO){
        JsonRes<Void> jsonRes = remoteStoreMainService.createStore(createStoreBO);
        if (Objects.isNull(jsonRes) || !Objects.equals(SysConstant.SUCCESS, jsonRes.getStatus())) {
            throw new DemoUserException("创建库存失败");
        }
    }
}
